function StarLine(scids,scide,times,timee) {
	this.scids = scids;
    this.scide = scide;
	this.times = times;
	this.timee = timee;
	this.useLefts = false;
    this.useLefte = false;
	this.timeDelta = 60.0;
	this.timeLimit = 0.0 ;
	this.ratio  = 0.0;
	this.color  = 0xffffff;
}

StarLine.prototype.isSame = function(starline) {
   if(this.times != starline.times || this.timee != starline.timee){
	   return false;
   }
   
   if(this.scids == starline.scids){
	   if(this.scide == starline.scide){
		   return true;
	   }
	   else{
		   return false;
	   }
   }
}

StarLine.prototype.clone = function() {
    var cloneData = new StarLine();
    cloneData.scids = this.scids;
    cloneData.scide = this.scide;
	cloneData.times = this.times;
	cloneData.timee = this.timee;
	cloneData.useLefts = this.useLefts;
	cloneData.useLefte = this.useLefte;

	cloneData.timeDelta = this.timeDelta;
	cloneData.timeLimit = this.timeLimit;
	cloneData.ratio  = this.ratio;
	cloneData.color  = this.color;
	return cloneData;
   
}

function StartLineS()
{
	//分成二十组，每组单独拆包
	this.starlines = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
}

StartLineS.prototype.add = function(starline,index)
{
	var length = this.starlines[index].length;
	if(length == 0){
	  this.starlines[index].push(starline);
	  return true;
	}
	else{
		
		for(var i = 0;i < length;i++)
		{
			if(this.starlines[index][i].isSame(starline))
			{
				return false;
			}
		}
		
		this.starlines[index].push(starline);
	    return true;
	}
}

//三轨道和四轨道的卫星纠正
StartLineS.prototype.process = function()
{
	var nametoid = window.starnametoid;
	var limit = window.starlinelimt;
	var sourcesLimit = limit.sources;
	var targetlimit = limit.targets;
	var slVector = [] ;
	var tgVector = [] ;
	
	for(var sl = 0;sl<sourcesLimit.length;sl++)
	{
		 slVector.push(sourcesLimit[sl].name);
	}
	
	for(var tl = 0;tl<targetlimit.length;tl++)
	{
		 tgVector.push(targetlimit[tl].name);
	}
	
	function GetStarsRealName(starName){
		
		var temp = starName;
		
		for(var i = 0;i<nametoid.locations.length ;i++)
		{
			var location = nametoid.locations[i];
			var name = location.name;
			var scid =   location.scid;
			
			if(temp == scid)
			{
				return name;
			}
		}
		return "";
	}
     
	var gui1 = ["BD3-M2","BD3-M1","BD3-M4","BD3-M3","BD2-M6","BD3-M14","BD3-M13"];
	var gui2 = ["BD3-M12","BD3-M5","BD3-M18","BD3-M17","BD3-M11","BD3-M6"];
	var gui3 = ["BD2-M2","BD3-M15","BD2-M3","BD3-M8","BD3-M7","BD3-M10","BD3-M9","BD3-M16"];
    
	var length = this.starlines.length;
	var addLines = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
	
	for(var i = 0;i < length;i++)
	{
	   var stars = this.starlines[i];
	   
	   for(var k = 0;k<stars.length;k++)
	   {
		   var line = stars[k];
		   
		   var  scidsName = GetStarsRealName(parseInt(line.scids));
		   var  scideName = GetStarsRealName(parseInt(line.scide));
		   
		   var indexStart = 0;
		   var indexEnd  = 0;
		   var indexNum0 = 0;
		   
		   for(var gui0k = 0;gui0k <gui1.length;gui0k++ )
		   {
			   if(scidsName == gui1[gui0k])
			   {
				   indexStart = gui0k;
				   indexNum0 ++;
			   }
			   else if(scideName == gui1[gui0k])
			   {
				   indexEnd = gui0k;
				   indexNum0 ++;
			   }
			   if(indexNum0 == 2)
			   {
				   if(indexStart > indexEnd)
				   {
					   line.ratio = -0.1;
				   }
				   else{
					   line.ratio = 0.1;
				   }
				   break;
			   }
		   } 
		   
		   var indexNum1 = 0;
		   indexStart = 0;
		   indexEnd  = 0;
		   for(var gui0k = 0;gui0k <gui2.length;gui0k++ )
		   {
			   if(scidsName == gui2[gui0k])
			   {
				   indexStart = gui0k;
				   indexNum1 ++;
			   }
			   else if(scideName == gui2[gui0k])
			   {
				   indexEnd = gui0k;
				   indexNum1 ++;
			   }
			   if(indexNum1 == 2)
			   {
				   if(indexStart > indexEnd)
				   {
					   line.ratio = -0.1;
				   }
				   else{
					   line.ratio = 0.1;
				   }
				   
				   break;
			   }
		   }
		   
		   var indexNum3 = 0;
		   indexStart = 0;
		   indexEnd  = 0;
		   
		   for(var gui0k = 0;gui0k <gui3.length;gui0k++ )
		   {
			   if(scidsName == gui3[gui0k])
			   {
				   indexStart = gui0k;
				   indexNum3 ++;
			   }
			   else if(scideName == gui3[gui0k])
			   {
				   indexEnd = gui0k;
				   indexNum3 ++;
			   }
			   if(indexNum3 == 2)
			   {
				   if(indexStart > indexEnd)
				   {
					   line.ratio = -0.1;
				   }
				   else{
					   line.ratio = 0.1;
				   }
				   
				   var lineLeft = line.clone();
				   lineLeft.useLefts = true;
	               lineLeft.useLefte = true;
				   lineLeft.scids = scidsName ;
		           lineLeft.scide = scideName;
				   addLines[i].push(lineLeft);
				   break;
			   }
		   } 
	
		 
		   var isOk = false;
		   for(var sll = 0;sll< slVector.length;sll++)
		   {
			   if(scidsName ==  slVector[sll])
			   {
				   for(var tll = 0;tll < tgVector.length;tll++)
				   {
					   if(scideName == tgVector[tll])
					   {
							line.useLefts = true;
							isOk = true;
							break;
					   }
				   }
			   }
			   else if(scideName ==  slVector[sll]){
				   
				   for(var tll = 0;tll < tgVector.length;tll++)
				   {
					   if(scidsName == tgVector[tll])
					   {
							line.useLefte = true;
							isOk = true;
							break;
					   }
				   }		   
			   }
			   
			   if(isOk == true)
			   {
				   break;
			   }
		   }
		  
		   line.scids = scidsName ;
		   line.scide = scideName;
	   }
	   
	}
	
	
	var num =  addLines.length;
	for(var kw = 0 ; kw<num;kw++)
	{
		var lines = addLines[kw];
		
		for(var ws = 0;ws<lines.length;ws++)
		{
			this.starlines[kw].push(lines[ws]);
		}
		
	}
		
}


//找出已经有的卫星数据，然后重复60次循环，进行数据时间的累加
//j 是table 的时间跨度 60分钟
//一个StartLineS 是一个小时内前一分钟的数据
var _gLoadOk = 0;

StartLineS.prototype.processDelta = function(j)
{
	var length = this.starlines.length;
	var tempData = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
	
	//一分钟内的数据
	for(var mk = 0;mk< length;mk++)
	{
		var length0 = this.starlines[mk].length;
		
		for(var i = 0;i<length0;i++)
		{
			tempData[mk].push(this.starlines[mk][i]);
		}
	}
		
	var minuteNum = parseInt(outDataTime);
	var num = parseInt(60.0)/minuteNum;
	var index = 0.0;
	this.datas = [];
	for(var w = 0; w<num; w++)
	{
		var data = new StartLineS();
		
		for(var k = 0;k<minuteNum;k++)
		{
			index = k+(w*minuteNum);
			
			var tempLength = tempData.length;
			
			for(var wk = 0;wk< tempLength;wk++)
			{
				var length2 = tempData[wk].length;
				
				for(var pk = 0;pk<length2;pk++)
				{
					var line = tempData[wk][pk];
					var lineClone = line.clone();
					lineClone.times += index*60;//60单位为妙
					lineClone.timee += index*60;//60单位为妙
					
					data.starlines[wk].push(lineClone);
				}
			}
		}
		this.datas.push(data);
		
		//data.tojson(w*minuteNum+j*60+".json",0);
		
	}
	
	for(var kk = 0;kk<this.datas.length;kk++)
	{
		this.datas[kk].tojson(kk*minuteNum+j*60+".json",0);
		//kk = _gLoadOk;
	}
	
}

function fake_click(obj)
{
	//var ev = document.createEvent('HTMLEvents');
	//ev.initEvent('click', false, true);
	
	var ev = document.createEvent("MouseEvents");
	ev.initMouseEvent("click",true,true,null,0,0,0,0,0,false,false,false,false,0,null);
	
	obj.dispatchEvent(ev);
	
}

StartLineS.prototype.exportData = function(path,data)
{   
	 var urlObject= window.URL || window.webkitURL || window;
	var export_blob = new Blob([data]);
	var save_link = document.createElementNS("http://www.w3.org/1999/xhtml",'a');
	save_link.href = urlObject.createObjectURL(export_blob);
	save_link.download = path;
	save_link.onclick = function()
	{
		_gLoadOk ++;
	}
	fake_click(save_link);
	
	/* var export_blob = new Blob([data]);
	var save_link = document.createElement('a');
	save_link.href = URL.createObjectURL(export_blob);
	save_link.download = path;
	save_link.style.display = 'none';
	document.body.appendChild(save_link);
	save_link.click();
	document.body.removeChild(save_link); */

}
StartLineS.prototype.tojson = function(path,num)
{
	var jsonObject1 = JSON.stringify(this);
	
/* 	 var file = new File([jsonObject1], path, { type: "text/plain;charset=utf-8" });
     saveAs(file,num,true); */
	
	this.exportData(path,jsonObject1);
}

StartLineS.prototype.fromjson = function(path)
{
	starlines.process("./assets/earth/planeStars.js");
	var jsonObject1 = JSON.stringify(starlines);
	console.log(jsonObject1);
}



